feat: add Swap and Clear methods (#13)#23
Merged
Merged
Conversation
Wrap sync.Map.Swap (Go 1.20) and sync.Map.Clear (Go 1.23) as methods on SyncMap. Swap mirrors the LoadAndDelete !loaded guard so it returns the typed zero V when the key is absent — matching the established pattern and preventing the nil-interface type-assertion panic path. Clear is a bare pass-through to sync.Map.Clear. Tests cover absent/present/zero-V-distinguished for Swap, empty-noop / populated-becomes-empty / subsequent-Store-works for Clear, plus a 100-goroutine contention test that asserts exactly one Swap observes loaded=false on a fresh key. Benchmarks added: BenchmarkSwap / SwapAbsent / SwapParallel and BenchmarkClear / ClearParallel. Header comment in syncmap_bench_test.go updated to cite both #13 and #14. CHANGELOG entry deferred to #17. Coverage remains at 100%.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wraps
sync.Map.Swap(Go 1.20) andsync.Map.Clear(Go 1.23) as methods onSyncMap. Zero API surface surprise — Swap mirrors theLoadAndDelete!loadedguard for typed-zero-on-miss; Clear is a bare pass-through.Closes #13.
Added methods
Verification
Agent gates
!loadedguard prevents nil-interface type-assertion panic; atomics + WaitGroup correct.SwapParallel/ClearParallel; both added in a follow-up edit. Now passing.Deferrals
bench.txtbaseline — test: add benchmarks, runnable examples, and bench-regression infrastructure #15.Test plan